﻿function mainOnOpen() {
  // Get Saved Values
  day=options.getValue("box_date");
  month=options.getValue("box_month");
  year=options.getValue("box_year");
  desc=options.getValue("box_desc");
  if (desc==''){
    lbl_event.innerText=LBL_GOTO_OPT;
  }else{
    lbl_event.innerText=desc;
  }
  bkgimg=options.getValue("box_img");
  if (bkgimg==''){
	  bkgimg='stock_images\\background.png';
  }
  box_img.src = bkgimg;
  transp=options.getValue("box_transp");
  if (transp==''){
	box_img.opacity='200';
  }else{
	box_img.opacity=transp;
  }
  switch (DATE_FORMAT){
    case 'MM-DD-YYYY':
     datevar=month+'-'+day+'-'+year;
     break;
    case 'DD-MM-YYYY':
     datevar=day+'-'+month+'-'+year;
     break;
  }
  realdate.innerText=datevar;
  doCount();
}
//Save size on exit

function doCount(){
	function lownumber(number){
		//Check if the number needs a leading zero
		if (number<10){
			return '0'+number;
		}else{
			return number;
		}
	}
	THEday = new Date(year,(month-1),day,0,0,0);
	today = new Date();
	if (today.getTime() < THEday.getTime( )) {
		rest = THEday.getTime() - today.getTime( );
		days=Math.floor(rest / (1000 * 60 * 60 * 24));
		hours=Math.floor((rest % (1000 * 60 * 60 * 24))/(1000 * 60 * 60));
		minutes=Math.floor((rest % (1000 * 60 * 60))/(1000 * 60));
		secs=Math.floor((rest % (1000 * 60))/(1000));
		box_day.innerText=days;
		box_time.innertext=lownumber(hours)+':'+lownumber(minutes)+':'+lownumber(secs);
	}else{
		box_day.innerText="00";
		box_time.innertext="00:00:00";
	}
	setTimeout("doCount();", 1000);
}